package Youcan_comparator;
import java.util.*;

import TreeSet_Stu.Stu;
public class Youcan_comparator {

	public static void main(String[] args) {
		//comparator 接口
		TreeSet<Stu> Stud = new TreeSet<Stu>(new Comparator<Stu>() {
		@Override
		public int compare(Stu s1, Stu s2) {
			
			int num = s1.getAge() - s2.getAge();
			int num2;
			if(num == 0) {
				num2 = s1.getName().compareTo(s2.getName());
				return num2;
			}
			return num;
		}
		});
		
		Stu s1 = new Stu("wangsicong", 1);
		Stu s2 = new Stu("wang", 2);
		Stu s3 = new Stu("wangg", 3);
		Stu s4 = new Stu("w", 3);
		Stu s5 = new Stu("waa", 3);
		Stu s6 = new Stu("w", 3);
		
		
		Stud.add(s3);
		Stud.add(s2);
		Stud.add(s1);
		Stud.add(s4);
		Stud.add(s6);
		
		
		
		for(Stu S : Stud) {
			System.out.println(S.getAge()+","+S.getName());
			
		}
		

}
}
